package org.example.springcloud.utils;


import org.example.springcloud.enums.ResultEnum;
import org.example.springcloud.vo.ResultVO;

/**
 * @Description: 返回工具类
 * @Author: y
 * @CreateDate: 12/28/20 2:08 PM
 * @Version: 1.0
 */
public class ResultVOUtil {
    public static ResultVO<Object> success() {
        ResultVO<Object> resultVO = new ResultVO<>();
        resultVO.setCode(ResultEnum.SUCCESS.getCode());
        resultVO.setMsg(ResultEnum.SUCCESS.getMsg());
        return resultVO;
    }

    public static ResultVO<Object> success(Object o) {
        return success().setData(o);
    }
    public static ResultVO<Object> success(Object o,String msg) {
        return success().setData(o).setMsg(msg);
    }
    public static ResultVO<Object> success(Object o, Long total) {
        return success().setData(o).setTotal(total);
    }

    public static ResultVO<Object> success(Object o, Long total, Integer totalPages) {
        return success().setData(o).setTotal(total).setTotalPages(totalPages);
    }

    public static ResultVO<Object> ok(String o) {
        return success().setMsg(o);
    }

    private static ResultVO<?> error(Integer code, String msg) {
        ResultVO<?> resultVO = new ResultVO<>();
        resultVO.setMsg(msg);
        resultVO.setCode(code);
        return resultVO;
    }
    public static ResultVO<?> error() {
        ResultVO<?> resultVO = new ResultVO<>();
        resultVO.setMsg(ResultEnum.DATA_IS_EMPTY.getMsg());
        resultVO.setCode(ResultEnum.DATA_IS_EMPTY.getCode());
        return resultVO;
    }

    public static ResultVO<?> error(ResultEnum resultEnum) {
        return error(resultEnum.getCode(), resultEnum.getMsg());
    }


    public static ResultVO<?> error(String msg) {
        return error(-1, msg);
    }
}
